{% extends 'app01/admin/home.html' %}

{% block content %}
    <div class="panel panel-default">
        <div class="panel-heading">增加用户</div>
        <div class="panel-body">
            <div class="container">
                <div class="row">
                    <div class="col-md-6 col-md-offset-3">
                        学号/职工号：
                        <input type="text" id="user_id" class="form-control" value="312/512xxxx">
                        邮箱：
                        <input type="text" id="email_id" class="form-control" value="312/512xxx@qq.com">
                        手机号：
                        <input type="text" id="phone_id" class="form-control" value="13xxxxxxxxx">
                        班级：
                        <input type="text" id="stu_class" class="form-control" value="老师无需写班级">
                        密码：
                        <input type="password" id="password" class="form-control" value="123">
                        <br>
                        <button class="btn btn-primary btn-sm btn-block" id="submit_the">注册用户</button>
                        <br>
                        <a type="button" class="btn btn-danger btn-sm btn-block" id="submit_clear">清空</a>
                        <br>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block js %}
    <script>
    let func = function(){
        //鼠标聚焦事件，清空默认值
             $('#stu_class').val('')
             $('#user_id').val('')
             $('#email_id').val('')
             $('#phone_id').val('')
            $('#password').val('')

    }
      //清空输入框的点击事件
        $('#submit_clear').click(function () {
            func()//调用该函数来实现清空
        })


        //发送Ajax请求，实现用户的创建
        $('#submit_the').click(function () {
            $.ajax({
                url:'/app01/admin_add_user/',
                type:'post',
                data: {
                    'user':$('#user_id').val(),'password':$('#password').val(),
                    'email':$('#email_id').val(),'phone':$('#phone_id').val(),'class':$('#stu_class').val()

                },
                success:function (array) {
                    if(array.code===100){
                        alert('注册成功')
                        func()//成功清空输入框

                    }
                    else{
                        alert(array.msg)
                    }

                }
            })

        });


        $('#id_editer').click(function () {

            let old_pwd = $('#id_old_pwd').val()
            let new_pwd = $('#id_new_pwd').val()
            let comfir_pwd = $('#id_confirm_pwd').val()
            $.ajax({
                url: '/app01/set_password/',
                type: 'post',
                data: {'old_pwd': old_pwd, 'new_pwd': new_pwd, 'confirm_pwd': comfir_pwd},
                success: function (attr) {
                    if (attr.code === 1000) {
                        alert(attr.msg)
                        window.location.reload()
                    } else if (attr.code === 2000) {
                        $('#error').text(attr.msg)
                    } else if (attr.code === 3000) {
                        $('#error').text(attr.msg)
                    }
                }
            })


        });


    </script>


{% endblock %}